package com.langfeiyes.pattern.strategy.demo;

import java.util.HashMap;
import java.util.Map;

/**
 * 美团App
 */
public class MeituanApp {
    //缓存支付策略
    private static Map<Integer, IPayStrategy> STRATEGY_MAP = new HashMap<>();
    static{
        STRATEGY_MAP.put(IPayStrategy.PAY_WECHAT, new WeChatPayStrategy());
        STRATEGY_MAP.put(IPayStrategy.PAY_ALI, new AliPayStrategy());
        STRATEGY_MAP.put(IPayStrategy.PAY_UNION, new UnionStrategy());
    }
    //订单支付
    public void orderPay(int type, int money){
        IPayStrategy payStrategy = STRATEGY_MAP.get(type);
        if(payStrategy != null){
            payStrategy.pay(money);
        }else{
            throw new RuntimeException("支付失败");
        }
    }
}
